package com.group.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.group.pojo.Delivery;
import com.group.pojo.Friends;
import com.group.service.FriendsService;
import com.group.utils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author group
 * @since 2021-09-06
 */
@RestController
@RequestMapping("/group/friends")
public class FriendsController {

    @Autowired
    private FriendsService friendsService;

    @ApiOperation(value = "按条件或全部查询信息")
    @GetMapping("/findAllfriends")
    public R findAllAddress(String ids,Integer pageNo,Integer pageSize){
        System.out.println(pageSize);
        if(pageNo == null){
            pageNo = 1;
        }
        if(pageSize == null){
            pageSize = 5;
        }

        PageHelper.startPage(pageNo,pageSize);
        /*if (ids==null){
            List<Friends> list = friendsService.findAllfriends(null);
            PageInfo<Friends> pageInfo = new PageInfo<>(list);
            return R.ok().data("pageInfo",pageInfo);
        }else {
            Friends friends = new Friends();
            String idstr[] = ids.split(",");
            if(!idstr[0].equals("-1")) {friends.setFriendsid( Integer.parseInt(idstr[0])  );}
            if(!idstr[1].equals("-1"))  {friends.setUserid( Integer.parseInt(idstr[1])  );}
            if(!idstr[2].equals("3")) {friends.setFriendsexamine( Integer.parseInt(idstr[2])  );}*/
            List<Friends> list = friendsService.findAllfriends(null);
            PageInfo<Friends> pageInfo = new PageInfo<>(list);
            return R.ok().data("pageInfo",pageInfo);
       /* }*/

    }

    @ApiOperation(value = "修改信息")
    @RequestMapping("/updateFriends")
    public R updateFriends(@RequestBody Friends friends){

        boolean flag = friendsService.updateFriends(friends);
        return flag? R.ok() : R.error();
    }

    @ApiOperation(value = "标记删除")
    @GetMapping("/deleteFriends")
    public R deleteFriends(String ids){
//        System.out.println(ids);
        String idstr[] = ids.split(",");
        boolean flag = friendsService.deleteFriends(idstr);
        return  flag? R.ok() : R.error();
    }

    @ApiOperation(value = "审核通过/不通过")
    @RequestMapping("/updateFriendsExamine")
    public R updateFriendsExamine(String ids,Integer friendsexamine){
        String idstr[] = ids.split(",");
        System.out.println(ids);
        System.out.println(friendsexamine);
        boolean flag = friendsService.updateFriendsExamine(idstr,friendsexamine);
        return  flag? R.ok() : R.error();
    }

    @ApiOperation(value = "添加功能")
    @PostMapping("/addFriends")
    public R addFriends(@RequestBody Friends friends){

        boolean flag = friendsService.addFriends(friends);
        return  flag? R.ok() : R.error();
    }

}

